﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RefundOrder.aspx.cs" Inherits="UI_Orders_RefundOrder" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>退款单管理</title>

    <script src="../../js/common.js" type="text/javascript"></script>
    <link href="../../css/admin.css" rel="stylesheet" type="text/css" />
    <link href="../../js/jquery.easyui/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../js/jquery.easyui/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../js/jquery.easyui/jquery.min.js" type="text/javascript"></script>
    <script src="../../js/jquery.easyui/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../js/jquery.easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
  
    <script type ="text/javascript" >
        $(function () {

            $("#ddlStatusId").combobox({
                editable: false
            });
            var defaultDate = Date.parse('1900/01/01');
            var _$refund = $("#refund");
            _$refund.datagrid({
                border: true,
                height: 345,
                width: 1100,
                title: '退款单列表...',
                remoteSort: false,
                nowrap: true,
                striped: false,
                url: "../../TableHanders.aspx?act=q&tid=44&type=0",
                sortName: 'OrderId',
                sortOrder: 'desc',
                loadMsg: "正在加载,请稍后...",
                frozenColumns: [[
                    { title: 'ck', field: 'CheckId', checkbox: true },
	                { title: 'ebay帐号', field: 'EbayUserId', width: 150, sortable: true,
	                    formatter: function (val, row, index) {
	                        var statusId = row.StatusId;
	                        var auditFlag = row.AuditFlag;
	                        if (statusId == 2) {                            
	                            return '<span style="color:red;">' + val + '</span>';
	                        }	                       
	                        else {
	                            return val;
	                        }
	                    }
                    },
	                { title: 'Rec_Num', field: 'OrderSalesRecordNumber', width: 85, sortable: true,
	                    formatter: function (val, row, index) {
	                        var statusId = row.StatusId;
	                        var auditFlag = row.AuditFlag;
	                        if (statusId == 2) {
	                            return '<span style="color:red;">' + val + '</span>';
	                        }
	                        else {
	                            return val;
	                        }
	                    }
                     }
				  ]],
                columns: [[
	                { title: '订单号', field: 'OrderId', width: 200, sortable: true },
	                { title: '退款单号', field: 'RefundId', width: 150, sortable: true },
                    { title: '交易编号', field: 'TransactionId', width: 150, sortable: true },
                    { title: '买家编号', field: 'BuyerId', width: 100, sortable: true },
                    { title: '买家全名', field: 'BuyerFullName', width: 150, sortable: true },
                    { title: '退款类别', field: 'AuditFlag', width: 80, formatter: function (val, rec) {
                        if (val == 1) {
                            return '审核前退款';
                        }
                        else if (val == 2) {
                            return '审核后退款';
                        }
                        else {
                            return val;
                        }
                    }
                    },
                    { title: '退款金额', field: 'RefundAmount', width: 80, sortable: true, align: 'right' },
                    { title: '货币', field: 'Currency', width: 30, sortable: true },
                    { title: '退款类型', field: 'TypeName', width: 300, sortable: true },
	                { title: '状态', field: 'StatusId', width: 90, sortable: true, formatter: function (val) {
	                    if (val == 0) {
	                        return "未审核";
	                    }
	                    else if (val == 1) {
	                        return "已审核";
	                    }
	                    else if (val == 2) {

	                        return '<span style="color:red;">' +"作废"+ '</span>';
	                    }
	                    else if (val == 3) {
	                        return "已付款";
	                    }
	                    else if (val == 4) {
	                        return "已二次退款";
	                    }
	                    else {
	                        return val;
	                    }
	                }
	                },
                    { title: '审核日期', field: 'Atime', width: 150, sortable: true },
	                { title: '投诉状态', field: 'DisputeType', width: 80, sortable: true, formatter: function (val) {
	                    if (val == 0) {
	                        return "未投诉";
	                    }
	                    else if (val == 1) {
	                        return "已投诉";
	                    }
	                }
	                },
	                { title: '责任部门', field: 'DepartmentName', width: 150, sortable: true },
	                { title: '退款日期', field: 'RefundDate', width: 120, sortable: true, formatter: function (val) {
	                    var d = Date.parse(val.replace("-", "/"));
	                    if (d == defaultDate) {
	                        return "";
	                    }
	                    else {
	                        return val;
	                    }
	                }
	                },
	               { title: '作废日期', field: 'InvalidDate', width: 120, sortable: true, formatter: function (val) {
	                   var d = Date.parse(val.replace("-", "/"));
	                   if (d == defaultDate) {
	                       return "";
	                   }
	                   else {
	                       return val;
	                   }
	               }
	               }
				]],
                pagination: true,
                rownumbers: true,
                singleSelect: false,
                pageList: [10, 15, 20],
                queryParams: {
                    "timeFrom": $("#dateFrom").datebox('getValue'),
                    "timeTo": $("#dateTo").datebox('getValue'),
                    "ebayUserId": $("#ddlebayUserId").combobox('getValue'),
                    "orderId":"",
                    "statusId": $("#ddlStatusId").combobox('getValue'),
                    "rec_number":""
                }
            });

            $("#btnQuery").click(function () {
                if (!$("#divContent").form('validate'))
                    return;
                var statusId = $("#ddlStatusId").combobox('getValue');
                var timeFrom = $("#dateFrom").datebox('getValue');
                var timeTo = $("#dateTo").datebox('getValue');
                var ebayUserId = $("#ddlebayUserId").combobox('getValue');
                var rec_number = $("#txtRec_number").val();
                _$refund.datagrid({
                    queryParams: {
                        "statusId": statusId,
                        "ebayUserId": ebayUserId,
                        "rec_number": rec_number,
                        "timeFrom": timeFrom,
                        "timeTo": timeTo
                    }
                });
            });
            $('#dateFrom').datebox({ formatter: function (date) {
                var y = date.getFullYear();
                var m = date.getMonth() + 1;
                var d = date.getDate();
                return y + "-" + m + "-" + d;
            }
            });
            $('#dateTo').datebox({ formatter: function (date) {
                var y = date.getFullYear();
                var m = date.getMonth() + 1;
                var d = date.getDate();
                return y + "-" + m + "-" + d;
            }
            });
            $("#btnshe").click(function () {
                var rows = _$refund.datagrid('getSelections');
                if (rows.length == 0) {
                    alert('请选择一个订单');
                    return;
                }
                var oids = "";
                for (i = 0; i < rows.length; i++) {
                    var oStatusId = rows[i].StatusId;
                    if (oStatusId != 0) {
                        alert("只有未审核的订单才可以操作");
                        return;
                    }
                    oids += rows[i].RefundId + ":" + rows[i].RefundAmount + ":" + rows[i].Currency + ",";
                }
                oids = oids.substring(0, oids.length - 1);
                var url = getRootPath() + "/UI/Orders/OrdersHandler.ashx?cmd=tkshe&oids=" + oids + "&ts=" + new Date().getTime();
                $.getJSON(url, function (data) {
                    var retData = EvalData(data);
                    var code = retData.retCode;
                    if (code == 0) {
                        alert('操作成功!');
                        _$refund.datagrid('reload');
                    }
                    else {
                        alert(retData.retMsg);
                    }
                });
            });
            $("#btnzfei").click(function () {
                var rows = _$refund.datagrid('getSelections');
                if (rows.length == 0) {
                    alert('请选择一个订单');
                    return;
                }
                var oids = "";
                for (i = 0; i < rows.length; i++) {
                    var oStatusId = rows[i].StatusId;
                    if (oStatusId != 0) {
                        alert("只有未审核的订单才可以操作！..");
                        return;
                    }
                    oids += rows[i].RefundId + ":" + rows[i].EbayUserId + ":" + rows[i].OrderSalesRecordNumber + ":" + rows[i].AuditFlag + ",";
                }
                oids = oids.substring(0, oids.length - 1);
                var url = getRootPath() + "/UI/Orders/OrdersHandler.ashx?cmd=tkzfei&oids=" + oids + "&ts=" + new Date().getTime();
                $.getJSON(url, function (data) {
                    var retData = EvalData(data);
                    var code = retData.retCode;
                    if (code == 0) {
                        alert('操作成功!');
                        _$refund.datagrid('reload');
                    }
                    else {
                        alert(retData.retMsg);
                    }
                });
            });

            //退款单维护窗口
            $("#RefundWindow").window({
                width: 350,
                height: 280,
                modal: true,
                shadow: false,
                closed: true,
                collapsible: false,
                minimizable: false,
                maximizable: false
            });

            //退款信息维护
            $("#btnxgai").click(function () {
                var rows = _$refund.datagrid('getSelections');
                if (rows.length == 0) {
                    alert('请选择一个退款单');
                    return;
                }
                if (rows.length != 1) {
                    alert('只能选择一退款单!');
                    return;
                }
                var oStatusId = rows[0].StatusId;
                if (oStatusId != 0) {
                    alert("只有未审核的退款单才可以修改！..");
                    return;
                }
                $("#txtoStatusId").val(oStatusId);
                $("#txtRefundMoneyEbayUserId").val(rows[0].EbayUserId);
                $("#txtRefundMoneyOrderId").val(rows[0].OrderId);
                $("#txtRefundMoney").val(rows[0].RefundAmount);
                $("#txtRefundId").val(rows[0].RefundId);
                $("#ddltkrefType").val(rows[0].RefundType);
                $("#ddltkdepartment").val(rows[0].BlameDepartments);
                $("#ddltkdisputeStatus").val(rows[0].DisputeType);
                $("#RefundWindow").window('open');
            });
            // 退款单维护取消
            $("#btnRefundMoneyCancel").click(function () {
                $("#RefundWindow").window('close');
            });
            //退款单维护确认
            $("#btnRefundMoneyOK").click(function () {
                var ebayuserId = $("#txtRefundMoneyEbayUserId").val();
                var orderId = $("#txtRefundMoneyOrderId").val();
                var totalPrice = $("#txtRefundMoney").val();
                var did = $("#ddltkdisputeStatus").val();
                var dtype = $("#ddltkrefType").val();
                var dpId = $("#ddltkdepartment").val();
                var refundId = $("#txtRefundId").val();
                var oStatusid = $("#txtoStatusId").val();
                var url = getRootPath() + "/UI/Orders/OrdersHandler.ashx?cmd=tkdxgai&ebayid=" + ebayuserId + "&oStatusid=" + oStatusid + "&orderid=" + orderId + "&tp=" + totalPrice + "&did=" + did + "&dtype=" + dtype + "&refundId=" + refundId + "&dpid=" + dpId + "&ts=" + new Date().getTime();
                $.getJSON(url, function (data) {
                    var retData = EvalData(data);
                    var code = retData.retCode;
                    if (code == 0) {
                        alert("操作成功!!");
                        $('#RefundWindow').window('close');
                        _$refund.datagrid("clearSelections");
                        _$refund.datagrid('reload');
                    }
                    else {
                        alert(retData.retMsg);
                    }
                });
            });

            //二次退款 修改时间：2012-8-6
            $("#btnxintkd").click(function () {
                var rows = _$refund.datagrid('getSelections');
                if (rows.length == 0) {
                    alert('请选择一个退款单');
                    return;
                }
                if (rows.length != 1) {
                    alert('只能选择一退款单!');
                    return;
                }
                var oStatusId = rows[0].StatusId;
                if (oStatusId != 1) {
                    alert("只有已审核的退款单才可以二次退款！..");
                    return;
                }
                $("#txtoStatusId").val(oStatusId);
                $("#txtRefundMoneyEbayUserId").val(rows[0].EbayUserId);
                $("#txtRefundMoneyOrderId").val(rows[0].OrderId);
                $("#txtRefundMoney").val(rows[0].RefundAmount);
                $("#txtRefundId").val(rows[0].RefundId);
                $("#ddltkrefType").val(rows[0].RefundType);
                $("#ddltkdepartment").val(rows[0].BlameDepartments);
                $("#ddltkdisputeStatus").val(rows[0].DisputeType);
                var ebayuserId = rows[0].EbayUserId;
                var orderId = rows[0].OrderId;
                var refundId = rows[0].RefundId;
                //获得二次退款余额
                var url = getRootPath() + "/UI/Orders/OrdersHandler.ashx?cmd=tkdjine&ebayid=" + ebayuserId + "&orderid=" + orderId + "&refundId=" + refundId + "&ts=" + new Date().getTime();
                $.getJSON(url, function (data) {
                    var retData = EvalData(data);
                    var code = retData.retCode;
                    if (code == 0) {
                        var amount = retData.fn;                      
                        $("#txtRefundMoney").val(amount);
                        $("#RefundWindow").window('open');
                    }
                    else {
                        alert(retData.retMsg);
                        _$refund.datagrid("clearSelections");
                    }
                });
            });
        });
	</script>	
</head>
<body> 
<div id="body">
<form id="formQuery" runat="server" style ="width :1100px;">
  <div class="div_Title">
        <span class="Body_Title">》》<%=this.Title %></span>
  </div>
  <div id="divContent" class="easyui-panel" title="请输入查询条件..." style="margin-bottom:5px;">
       <table >
             <tr>
                <td>ebay帐号:</td>
                <td>
            	    <select  id="ddlebayUserId" runat="server" class="easyui-combobox" style="width:200px;"></select>
                </td>
                <td>Rec_Num:</td>
                <td>
            	    <input id="txtRec_number" runat="server" style="width:120px;" />
                </td>
                <td > 状态:</td>
                <td >
                    <select id="ddlStatusId" runat="server" class="easyui-validatebox" enableviewstate="false" style ="width :110px;"/>
               </td>
                <td>退款日期:</td>
                <td>
                    <input type ="text" ID ="dateFrom" runat="server" class ="easyui-datebox" required="true" style ="width :120px;"  /></td>
                <td> - </td>
                <td>
                    <input type ="text" ID="dateTo"  runat="server" class ="easyui-datebox" required="true" style ="width :120px;" /></td>
                <td> 
                    <a id="btnQuery"  href ="#"  class="easyui-linkbutton" icon="icon-search" >Query</a></td>
                <td> 
                    <asp:LinkButton ID="btnExport" CssClass = "easyui-linkbutton"  icon="icon-redo" 
                            Text="导出" runat="server" onclick="btnExport_Click"></asp:LinkButton>
                </td>
            </tr>
         </table>
    </div>
  <table  id="refund"></table>
  <div id ="divOperating"  class="easyui-panel" title="数据操作..." style="margin-bottom:5px;">
     <table >
           <tr>
           <td>当日退款总额:</td>
           <td><input type ="text" ID="txtTotalRefundAmount" disabled="true" runat="server" style ="width :100px" /></td>
            <td >
            <a class = "easyui-linkbutton" href ="#" id = "btnxgai">退款单修改</a>
            <a class = "easyui-linkbutton" href ="#" id = "btnshe">审核</a>
            <a class = "easyui-linkbutton" href ="#" id = "btnzfei">作废</a>
            <a class = "easyui-linkbutton" href ="#" id = "btnxintkd">二次退款</a>
            </td>
          </tr>
      </table>
   </div>
    <div id = "RefundWindow" title = "退款信息维护">
        <input type="hidden" id="txtoStatusId" />
        <table>
            <tr>
                <td>
                    Ebay帐号:
                </td>
                <td>
                    <input  id = "txtRefundMoneyEbayUserId" readonly = "readonly"  style = "width:200px"/>                  
                </td>             
            </tr>
            <tr>
                <td>
                    订单号:
                </td>
                <td>
                    <input  id = "txtRefundMoneyOrderId" readonly = "readonly"  style = "width:200px"/>
                </td>             
            </tr>
             <tr>
                <td>
                    退款单号:
                </td>
                <td>
                    <input  id = "txtRefundId" readonly = "readonly"  style = "width:200px"/>
                </td>             
            </tr>
            <tr>
                <td>
                    退款金额:
                </td>
                <td>
                    <input  id = "txtRefundMoney" class = "easyui-numberbox" runat= "server" require = "true" precision = "2"  style = "width:200px"/>
                </td>                
            </tr>
            <tr>
                <td>
                    退款类型:
                </td>
                <td>
                    <select id = "ddltkrefType" style = "width:206px" runat= "server" ></select>
                </td>
            </tr>
            <tr>              
                <td>
                    责任部门:
                </td>
                <td>
                    <select id = "ddltkdepartment" style = "width:206px" runat= "server" name="D1" ></select>
                </td>
            </tr>
            <tr>         
                <td>
                    投诉状态:
                </td>
                <td>
                    <select id = "ddltkdisputeStatus" runat = "server" style = "width:206px"></select>
                </td>
            </tr>
        </table>
         <div style="text-align:right;height:30px;line-height:30px; padding:10px;">
			<a id="btnRefundMoneyOK" class="easyui-linkbutton" iconCls="icon-ok" href="javascript:void(0)" >Ok</a>
			<a id="btnRefundMoneyCancel" class="easyui-linkbutton" iconCls="icon-cancel" href="javascript:void(0)">Cancel</a>
		</div>
    </div>   
   </form>
 </div> 
</body>
</html>